package com.example.sqlite.greendao;

import java.util.List;

public class AddressRepository {
    private AddressDao addressDao;

    public AddressRepository(MyApplication app) {
        DaoSession daoSession = app.getDaoSession();
        addressDao = daoSession.getAddressDao();
    }

    public void insert(Address address) {
        addressDao.insert(address);
    }

    public void delete(Address address) {
        addressDao.delete(address);
    }

    public void update(Address address) {
        addressDao.update(address);
    }

    public List<Address> getAll() {
        return addressDao.loadAll();
    }

    public List<Address> getByName(String name) {
        return addressDao.queryRaw("where name=?", name);
    }

    //查询 name相似的 Address
    public List<Address> getLikeName(String name) {
        return addressDao.queryBuilder()
                .where(AddressDao.Properties.Name.like(name))
                .build()
                .list();
    }
}
